var User = require('../model/user').User
const md5 = require('md5')
const result = require('../utils/result')
const Recharge = require('../model/recharge')
const Withdraw = require('../model/withdraw')
const Bills = require('../model/user').Bills
/**
 * 充值列表
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.RechargeList = async (req,res)=>{

    let _g = await Recharge.findAll()
    res.json(result(0,'success',_g))
}
/**
 * 提现列表
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.Withdraw = async (req,res)=>{

    let _g = await Withdraw.findAll()
    res.json(result(0,'success',_g))
}
/**
 * 提现审核通过
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.WithdrawPass = async (req,res)=>{
    let id =req.query.id;
    let uid = req.query.uid
    let _g = await Withdraw.update({status:1},{where:{
        status: 0,
            id:id,
            uid:uid
        }}).then(v=>{
            if(v[0] == 1){
                res.json(result(0,'success','审核通过'))
            }else{
                res.json(result(0,'success','审核不通过'))
            }
    }).catch(e=>{
        res.json(result(-1,'fail','发生未知错误'))
    })


    // res.json(result(0,'success',_g))
}
/**
 * 提现审核不通过
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.WithdrawNoPass = async (req,res)=>{
    let id =req.query.id;
    let uid = req.query.uid
    let _g = await Withdraw.update({status:2},{where:{
            status: 1,
            id:id,
            uid:uid
        }}).then(v=>{
        if(v[0] == 1){
            res.json(result(0,'success','操作成功'))
        }else{
            res.json(result(0,'success','操作失败'))
        }
    }).catch(e=>{
        res.json(result(-1,'fail','发生未知错误'))
    })


    // res.json(result(0,'success',_g))
}
/**
 * 我的账单
 * @param req
 * @param res
 * @returns {Promise<void>}
 * @constructor
 */
exports.user_bill = async (req,res)=>{
    let uid = req.query.uid
    if(!uid){
        res.json(result(0,'fail','缺少参数uid'))
        return;
    };
    let c = await Bills.findAll({where:{uid}})
    let G = await Recharge.findAll({where:{uid}})
    let g = await Withdraw.findAll({where:{uid}})
    let data =G.concat(g);
    data = data.concat(c)
    res.json(result(0,'success',data))

}
